package com.example.demo.controller;

import com.example.demo.entity.People;
import com.example.demo.mapper.PeopleMapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

@Api(tags="people")
@RestController
@EnableSwagger2
public class PeopleController {
    @Autowired
    private PeopleMapper peopleMapper;
    @ApiOperation(value = "添加用户")
    @GetMapping("/addpeople")
    public int AddUser(People people){
        if (people !=null){
                List<People> list = new ArrayList<>();
                list = peopleMapper.getAll();
                Iterator<People> it = list.iterator();
                while(it.hasNext())
                {
                    People people1 = (People) it.next();
                    String x = people.getPname();
                    String y = people1.getPname();
                    System.out.println("x=" + x + ",y=" + y);
//                    if (x == y){
//                        System.out.println("kjhjhjgyuhjklhgfdfhgjkljhgfdfhgj");
//                    }else{
//                        System.out.println("@41241");
//                    }
                }
        }
    return peopleMapper.insertUser(people);
    }
    @ApiOperation(value = "用户查询")
    @GetMapping("/getpeople")
    public List<People> getAll(){
        return peopleMapper.getAll();
    }
    @ApiOperation(value = "删除用户")
    @GetMapping("/deletepeople")
    public int delete(int id){
        return peopleMapper.delete(id);
    }
    @ApiOperation(value = "更新用户姓名")
    @GetMapping("/updatepeople")
    public int update(People people){
        return peopleMapper.update(people);
    }
}
